<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/newbase.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <script src="__STATIC__/password/passwordBox.min.js"></script>
    <script src="__STATIC__/password/md5.js"></script>
    <title>充值</title>
    <style>
        .pay_way{  width: 100%;  height: auto;  background: white;  margin-top: 5px;  }
        .pay_way>div{  width: 94%;  margin: 0 auto;  overflow: hidden;  }
        .pay_way .title{  float: left;  font-size: 14px;  line-height: 44px;  }
        .pay_way .way{  float: right;  overflow: hidden;  }
        .pay_way .way .radio + label {  -webkit-appearance: none;  background: url("__STATIC__/img_user/1234.png") no-repeat center left;  background-size: 14px 14px;  padding: 10px 7px 10px 22px;
            display: inline-block;  font-size: 14px;  line-height: 24px;  font-weight: normal;  margin-bottom: 0;  }
        .pay_way .way .radio:checked + label {  background: url("__STATIC__/img_user/123.png") no-repeat center left;  background-size: 14px 14px;  }
        .pay_way .way>div{  float: left;  margin-left: 10px;  }
        .pay_way .way>div:first-child{  margin-left: 0;  }
        .money{  padding: 0 0 10px 30px;  position: relative;  }
        .money input{  display: block;  font-size: 12px;  line-height: 34px;  text-indent: 5px;  border: none;  outline: none;  color: #333;  width: 100%;  border-bottom: 1px solid #E9E9E9;  }
        .money span{  position: absolute;  font-size: 24px;  line-height: 34px;  color: #333;  left: 0;  top:0;  }
        .confirm{  width: 94%;  margin: 30px auto 0;  font-size: 16px;  line-height: 40px;  background: #E73F09;  text-align: center;  border-radius: 4px;  }
        .confirm a{  color: white;  }
    </style>
</head>
<body>

<div class="wrap-shop">
    <div class="header">
        <p>充值</p>
        <img src="__STATIC__/img/back.png" class="back" onclick="back_url()">
    </div>

    <div class="pay_way">
        <div>
            <div class="title">充值方式</div>
            <div class="way">
                {eq name="$is_weixin" value="1"}
                <div><input type="radio" class="radio" name="radio" id="radio-2" value="2" checked><label for="radio-2">微信</label></div>
                {else/}
                <div><input type="radio" class="radio" name="radio" id="radio-1" checked value="1"><label for="radio-1">支付宝</label></div>
                {/eq}
            </div>
        </div>
    </div>
    <div class="pay_way">
        <div>
            <div class="title" style="float: none;">充值金额</div>
            <div class="money">
                <input type="number" placeholder="请输入金额" name="price">
                <span>￥</span>
            </div>
        </div>
    </div>
    <div class="confirm" onclick="javascript:confirm_recharge()" style="color: #fff;">确认充值</div>




</div>
<script src="__STATIC__/js/layer_mobile/layer.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>

    function confirm_recharge(){
        var price = $("[name='price']").val();
        var zz = /^-?\d+\.?\d{0,2}$/;
        if (price == ''){
            layer.open({content:'充值金额不能为空',skin:'msg',time:2});
            return false;
        }else if(! zz.test(price)){
            layer.open({content:'充值金额格式有误',skin:'msg',time:2});
            return false;
        }else if (price < 0.01){
            layer.open({content:'充值金额格式有误',skin:'msg',time:2});
            return false;
        }
        var pay_type = $("[type='radio']:checked").val();

        //支付宝充值
        if (pay_type == 1){
            $.ajax({
                url : "{:url('mobile/alipay/rechage')}",
                type:'post',
                dataType:'html',
                data:{'price':price,'body' : '{$information}' , 'order_number':'{$order_number}'},
                success:function (data) {
                    $('#alipay').html(data);
                },
                error: function () {
                    layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
                }
            });
            //微信充值
        } else if (pay_type == 2){
            window.location.href = "{:url('mobile/recharge/index')}?pay_money="+price;
        }
    }

    //返回路径
    function back_url(){
        window.location.href = sessionStorage.getItem('recharge_back_url');
    }

   if (window.location.href.indexOf('pay_money') > -1){
        callpay();
   }

    function callpay() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        } else {
            onBridgeReady(data);
        }
    }

    function onBridgeReady(){
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',JSON.parse('{$param}'),
            function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                    //window.location.href = "{:url('mobile/recharge/index')}";
                    window.location.href = "{:url('mobile/user_info/wallet_details',['type' => 1])}";
                }
            }
        );
    }
</script>
</body>
</html>